package com.zhouxiaoge.source;

import com.zhouxiaoge.Event;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author 周小哥 gqzmy@163.com 2022/7/21
 */
public class TransformSimpleAggTest {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Event> streamSource = env.fromElements(
                new Event("Mary", "/home", 1000L),
                new Event("Alice", "/home", 2000L),
                new Event("Bob", "/pay", 3000L),
                new Event("Bob", "/home", 4000L),
                new Event("Mary", "/order?id=100", 9000L),
                new Event("Alice", "/home", 6000L),
                new Event("Mary", "/cart", 7000L)
        );

        KeyedStream<Event, String> keyedStream = streamSource.keyBy(event -> event.user);
        SingleOutputStreamOperator<Event> streamOperator = keyedStream.maxBy("time");
        streamOperator.print();

        env.execute();
    }
}
